const query = require("../db/query");

// 获取患者 模糊搜索
const Getpatient = async (params) => {
    let sql = `select * from patient where patientid LIKE '%${params.patientid}%' and name LIKE '%${params.name}%' and gender LIKE '%${params.gender}%' and age LIKE '%${params.age}%' ORDER BY patientid desc`
    return await query(sql)
}

//  添加患者
const Addpatient = async (params) => {
    let sql = `INSERT INTO patient(name, gender, age, contactinformation, address,symptom, medicalhistory, familymedicalhistory, drugallergies, currentmedications) VALUES ('${params.name}', '${params.gender}', ${params.age}, '${params.contactinformation}', '${params.address}','${params.symptom}', '${params.medicalhistory}', '${params.familymedicalhistory}', '${params.drugallergies}', '${params.currentmedications}')`;
    return await query(sql)
}

// 删除患者
const Delpatient = async (params) => {
    let sql = `DELETE FROM patient WHERE patientid = ${params.patientid}`
    console.log(sql);

    return await query(sql)
}

// 修改患者信息
const Updatepatient = async (params) => {
    let sql = `UPDATE patient SET symptom ='${params.symptom}', name='${params.name}',gender='${params.gender}',age = '${params.age}', contactinformation='${params.contactinformation}',address='${params.address}',medicalhistory='${params.medicalhistory}',familymedicalhistory='${params.familymedicalhistory}',drugallergies='${params.drugallergies}',currentmedications='${params.currentmedications}' WHERE patientid = ${params.patientid}`
    return await query(sql)
}

module.exports = {
    Getpatient,//获取患者
    Addpatient,//添加患者
    Delpatient,//删除患者
    Updatepatient,//修改患者
}